# 要求随机返回一种商品，要求商品被返回的概率与其库存成正比。请描述实现的思路或者直接写一个实现的函数


import random

stock = {"袜子": 10, "鞋子": 20, "拖鞋": 30, "项链": 40}


def probability():
    goods = []
    for x, y in stock.items():
        goods = goods + [x for _ in range(y)]

    return random.sample(goods, k=1)


extract = probability()

print(extract)

# 实现的很好，实际的测试代码可以像老师这样写。更容易看见结果。
temp = {}
for i in range(100000):
    extract = probability()[0]
#     print(extract)
    if temp.get(extract) is None:
        temp[extract] = 1
    else:
        temp[extract]+=1
print(temp)